﻿using System.Collections.Generic;
using System.Linq;
using Infrastructure;

namespace Domain
{
    public class BorrowInfoRepository : Repository<BorrowInfo, UniqueId>, IBorrowInfoRepository
    {
        public IList<BorrowInfo> FindNotReturnedBorrowInfos(UniqueId borrowerId)
        {
            return GetAll().Where(borrowInfo => borrowInfo.Borrower.Id == borrowerId && borrowInfo.ReturnTime == null).ToList();
        }
        public BorrowInfo FindNotReturnedBorrowInfo(UniqueId borrowerId, UniqueId bookId)
        {
            return GetAll().FirstOrDefault(borrowInfo => borrowInfo.Borrower.Id == borrowerId && borrowInfo.Book.Id == bookId && borrowInfo.ReturnTime == null);
        }
    }
}
